[Bernard Wan De Yuan] iP#461
Conversation
# Conflicts: # src/main/java/Duke.java # src/main/java/Task.java # text-ui-test/EXPECTED.TXT
# Conflicts: # src/main/java/duke/DukeException.java # src/main/java/duke/TaskList.java
| import duke.DukeException; | ||
| import duke.Task; | ||
| import duke.TaskList; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.ArrayList; |
There was a problem hiding this comment.
Should java related imports come before duke?
| @@ -0,0 +1,42 @@ | |||
| package duke.Command; | |||
|
|
|||
| import duke.*; | |||
There was a problem hiding this comment.
I think perhaps can consider importing individual classes instead of using wildcard import!
| if(type.equals("todo")) { | ||
| task = new Task.Todo(description, false); | ||
|
|
||
| } else if(type.equals("deadline")) { | ||
| String[] temp = description.split("by ", 2); | ||
| task = new Task.Deadline(temp[0], false, temp[1]); | ||
|
|
||
| } else if(type.equals("event")) { | ||
| String[] temp = description.split("at ", 2); | ||
| task = new Task.Event(temp[0], false, temp[1]); |
There was a problem hiding this comment.
Maybe can consider using enum for this!
| * Loads task data from storage | ||
| * | ||
| * @return ArrayList of tasks | ||
| * @throws DukeException |
There was a problem hiding this comment.
Feel like the condition when the DukeException is thrown should be specified here :))
| this.status= status; | ||
| } | ||
|
|
||
| public static class Todo extends Task{ |
There was a problem hiding this comment.
Should there be a whitespace before the curly braces?
| if (input.equals("bye")) { | ||
| return new ExitCommand(); | ||
| } else if (input.equals("list")) { | ||
| return new ListCommand(); | ||
| } else if (first_word.equals("done")) { | ||
| int index; | ||
| try { | ||
| index = Integer.parseInt(input.split(" ")[1]) - 1; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| throw new DukeException("Sorry, please enter an integer after 'done'. (e.g. done 2)"); | ||
| } | ||
| return new DoneCommand(index); | ||
| } else if (first_word.equals("delete")) { | ||
| int index; | ||
| try { | ||
| index = Integer.parseInt(input.split(" ")[1]) - 1; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| throw new DukeException("Sorry, please enter an integer after 'delete'. (e.g. delete 2)"); | ||
| } | ||
| return new DeleteCommand(index); | ||
| } else if (first_word.equals("find")){ | ||
| String remaining; | ||
| try { | ||
| remaining = input.split(" ", 2)[1]; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| throw new DukeException("Sorry, please enter a keyword after 'find'."); | ||
| } | ||
| return new FindCommand(remaining); | ||
| } else { | ||
| String remaining; | ||
| try { | ||
| remaining = input.split(" ", 2)[1]; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| throw new DukeException("Sorry, tasks must include descriptions."); | ||
| } | ||
| return new AddCommand(first_word, remaining); | ||
| } |
There was a problem hiding this comment.
Perhaps we can use enum here to simplify the logic here! Also, personally I fell that all the try-catch statement here can be abstracted to other class method e.g. createDone() etc. to prevent arrowhead style code, and that one single catch for ArrayIndexOutOfBoundsException could be used for the entire method. Don't know if I articulate my idea in a very accurate way 😂
| String line = reader.nextLine(); | ||
| String[] data = line.split(" \\| "); | ||
| switch (data[0]) { | ||
| case "todo": |
There was a problem hiding this comment.
Should case be on the same indent level as switch?
chengseong
left a comment
There was a problem hiding this comment.
LGTM! I think the code is very clean and easy to read and there is very clear abstraction between classes. Well done!
| @@ -0,0 +1,30 @@ | |||
| package duke.Command; | |||
|
|
|||
| import duke.*; | |||
There was a problem hiding this comment.
I think you should import package by package, for example import duke.TaskList rather than using import duke.*
| public abstract class Command { | ||
| public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException; | ||
|
|
||
| public abstract boolean isExit(); |
There was a problem hiding this comment.
You might want to consider setting isExit to False in the abstract, then only changing it to True when it is an ExitCommand. This way you do not have to constantly check what Command it is
Gradle run and shadowJar tasks are not functioning as intended. This should be fixed for ease of use and to create a new JAR release. Let's edit the build.gradle for proper main class declaration. Also,let's fix any checkstyle errors that might inhibit the build process.
There are some left over code from before GUI was implemented. These leftover code that is not used should be removed to improve code quality and readability. Let's check through the code and remove any unused methods or other files.
branch-A-Assertions
Branch a code quality
DUKE
Hi this is my Duke program! It's
Steps to use:
Features:
Sample code
main: